<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    > 

      <el-form-item label="需求名称" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入需求名称"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>

      <el-form-item label="需求类别" prop="types">
        
        <el-select v-model="queryParams.typeId" placeholder="请选择需求类别" clearable   class="!w-240px">
          <el-option v-for="type in types" :key="type.id" :label="type.name" :value="type.id" />
        </el-select> 
      </el-form-item> 
      <el-form-item label="需求时间" prop="createDate">
        <el-date-picker
          v-model="queryParams.createDate"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery">
          <Icon icon="ep:search" class="mr-5px" />
          搜索
        </el-button>
        <el-button @click="resetQuery">
          <Icon icon="ep:refresh" class="mr-5px" />
          重置
        </el-button>
        
        <el-button v-hasPermi="['pay:app:create']" plain type="primary" @click="openForm('create')">
          <Icon class="mr-5px" icon="ep:plus" />
          新增
        </el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list"> 
      <el-table-column label="需求名称" align="center" prop="title"   />
      <el-table-column label="需求类型" align="center" prop="type"   />
      <el-table-column label="描述/尺寸" align="center" prop="description" />
      <el-table-column label="数量" align="center" prop="num" />
      <el-table-column label="人天" align="center" prop="day" />
      <el-table-column label="供应商名称" align="center" prop="gongyingshang"/>
      <el-table-column label="预算成本" align="center" prop="money"/> 
      <el-table-column label="需求时间" align="center" prop="created_at"/> 
   
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
</template>

<script lang="ts" setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import * as RecordApi from '@/api//member/point/record'

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  bizType: undefined,
  title: null,
  createDate: [],
  userId: NaN
}) 

const types = reactive([
  {id:"1",name:"立项"},{id:"2",name:"变更"} 
]);
const queryFormRef = ref() // 搜索的表单

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await RecordApi.getRecordPage(queryParams)
    list.value = [{title:'沙盘',money:100,description:'描述',type:'立项',num:1,day:'-',gongyingshang:'张三供应商',created_at:'2024-11-14 10:00:00'}]
    total.value = 1
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

const { userId } = defineProps({
  userId: {
    type: Number,
    required: true
  }
})

/** 初始化 **/
onMounted(() => {
  queryParams.userId = userId
  getList()
})
</script>
